{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2024 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

<div class="asset {{ bg }}">
   {{ include('components/form/header.html.twig') }}

   {% set rand = random() %}
   {% set params  = params ?? [] %}
   {% set field_options = {} %}

   <div class="card-body d-flex flex-wrap">
      <div class="col-12 col-xxl-{{ item_has_pictures ? '9' : '12' }} flex-column">
         <div class="d-flex flex-row flex-wrap flex-xl-nowrap">
            <div class="row flex-row align-items-start flex-grow-1">
               <div class="row flex-row">
                  {% block form_fields %}
                     {{ fields.textField('name', item.fields['name'], __('Name')) }}
                     {% if not item.isNewItem() %}
                        {{ fields.readOnlyField('identifier', item.fields['identifier'], __('Client ID')) }}
                     {% endif %}
                     {% if not item.isNewItem() %}
                        {{ fields.passwordField('secret', item.fields['secret'], __('Client Secret'), {
                           is_disclosable: true,
                           readonly: true,
                        }) }}
                     {% endif %}

                     {% if allowed_scopes is defined and allowed_scopes is not empty %}
                        {{ fields.dropdownArrayField('scopes', null, allowed_scopes, __('Scopes'), {
                           multiple: true,
                           values: item.fields['scopes'],
                        }) }}
                     {% endif %}

                     {{ fields.dropdownArrayField('grants', null, {
                        'password': __("Password"),
                        'client_credentials': __("Client credentials"),
                        'authorization_code': __("Authorization code"),
                     }, __('Grants'), {
                        multiple: true,
                        values: item.fields['grants']|default(['authorization_code']),
                     }) }}

                     {{ fields.textareaField(
                        'comment',
                        item.fields['comment'],
                        _n('Comment', 'Comments', get_plural_number()),
                        field_options
                     ) }}
                  {% endblock %}
               </div> {# .row #}
            </div> {# .row #}
         </div> {# .flex-row #}
      </div>
   </div> {# .card-body #}

   {{ include('components/form/buttons.html.twig') }}
</div>
